package Listeners;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import GUI.AuthorToolPanel;
import GUI.ConferenceWizardFrame;
import Model.Conference;
import Model.Paper;
import Model.User;

/**
 * Listener for the "Remove Paper" button in the AuthorToolPanel.
 * 
 * Allows the user(Author) to remove a paper submission from the conference
 * if they desire.  Prompts the user with a confirm message when attempting
 * to remove a paper.
 * 
 * @author Paul Schultz
 * @version 11/30/2012
 */
@SuppressWarnings("serial")
public class RemovePaperListener extends AbstractAction
{
  Paper my_paper;
  Conference my_conference;
  ConferenceWizardFrame my_frame;
  User my_user;

  /**
   * Constructs a new RemovePaperListener.
   * 
   * @param the_conf The conference the paper is in.
   * @param the_paper The paper to be removed from the conference.
   * @param the_user The Author of the paper to be removed.
   * @param the_frame The master frame for the application.
   */
  public RemovePaperListener(Conference the_conf, Paper the_paper,
      User the_user, ConferenceWizardFrame the_frame)
  {
    my_paper = the_paper;
    my_conference = the_conf;
    my_frame = the_frame;
    my_user = the_user;
  }
  
  /**
   * Prompts the user to confirm the decision to delete the paper.
   * If yes is chosen, the paper is deleted.  Choosing no, will
   * make not remove the paper.
   */
  @Override
  public void actionPerformed(ActionEvent arg0)
  { 
    int choice = JOptionPane.showConfirmDialog(my_frame, "Are you sure you want to remove the paper?"
        , "Paper Removal Confirmation", JOptionPane.YES_NO_OPTION);
    
    if (choice == JOptionPane.YES_OPTION)
    {
      my_conference.removePaper(my_paper);
      my_frame.setCurrentPanel(new AuthorToolPanel(my_conference, my_user, my_frame));
    }
    
    
  }

}
